package uk.co.wroedevelopments.semanticworkbench.model;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.emf.ecore.EObject;
import org.xtext.example.semDsl.DefC;
import org.xtext.example.semDsl.NewAttribute;
import org.xtext.example.semDsl.NewSub;
import org.xtext.example.semDsl.SemDslPackage;
import org.xtext.example.semDsl.Ontology;
import org.xtext.example.semDsl.Name;
import org.xtext.example.semQryDsl.SemQryDslPackage;

public class OntologyUtils {

	public List<DefC> getDefConcepts(Ontology ont) {
		List<DefC> result = new ArrayList<DefC>();
		for (EObject e : ont.getElements()) {
			if (isEClass(e,SemDslPackage.DEF_C)) result.add((DefC) e);
		}
		return result;
	}

	private boolean isEClass(EObject e, int classID) {
		return (e.eClass().eContainer() == SemDslPackage.eINSTANCE && e.eClass().getClassifierID() == classID);
		
	}

	public List<NewSub> getNewSubList(Ontology ont) {
		List<NewSub> result = new ArrayList<NewSub>();
		for (EObject e : ont.getElements()) {
			if (isEClass(e, SemDslPackage.NEW_SUB)) result.add((NewSub) e);
		}
		return result;
	}

	public List<NewAttribute> getNewAttributeList(Ontology ont) {
		List<NewAttribute> result = new ArrayList<NewAttribute>();
		for (EObject e : ont.getElements()) {
			if (isEClass(e, SemDslPackage.NEW_ATTRIBUTE)) result.add((NewAttribute) e);
		}
		return result;
	}

	public List<Name> getNameList(Ontology ont) {
		List<Name> result = new ArrayList<Name>();
		for (EObject e : ont.getElements()) {
			if (isEClass(e, SemDslPackage.NAME)) result.add((Name) e);
		}
		return result;
		
	}

}
